package com.vdongchina.miniapp.http.dto;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vdongchina.miniapp.commons.MiniAppException;
import com.vdongchina.miniapp.utils.JsonUtils;
import lombok.Data;

import java.io.Serializable;
import java.util.Objects;

/**
 * Copyright (C)
 * FileName: AppResp
 * Author:   maokai
 * Date:     2021/8/12 14:23
 * Description: 相应结果
 */
@Data
public class ServiceResp implements Serializable {
    static Long successCode = 0L;
    @JsonAlias(value = "err_no")
    private Long errNo;
    @JsonAlias(value = "err_tips")
    private String errTips;

    public void success() throws MiniAppException {
        if (Objects.nonNull(errNo) && !successCode.equals(errNo)) {
            String format = String.format("接口请求异常【 %d : %s】", errNo, errTips);
            throw new MiniAppException(format);
        }
    }
}
